import React, { useEffect } from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';
import PrivateRoute from '@/layouts/components/PrivateRoute/PrivateRoute';
import AppLayout from '@/layouts/Index';
import { setToken } from '@/utils/auth';

// 懒加载页面组件
const User = React.lazy(() => import('./pages/User/User'));
const Login = React.lazy(() => import('./pages/Login/Login'));
const Page404 = React.lazy(() => import('./pages/404/Error'));

const App = () => {
  useEffect(() => {
    // 模拟设置token
    setToken('mock-token-123');
  }, []);

  return (
    <Switch>
      <Route path="/login" component={Login} />
      <PrivateRoute path="/">
        <AppLayout>
          <Switch>
            <Route exact={true} path="/" render={() => <Redirect to="/user" />} />
            <Route path="/user" component={User} />
            <Route component={Page404} />
          </Switch>
        </AppLayout>
      </PrivateRoute>
    </Switch>
  );
};

export default App;
